/**
 * 
 */
package org.jackysoft.struts2;

import java.util.Collection;
import java.util.Map;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jackysoft.entity.User;
import org.jackysoft.entity.nosql.OperationLog;
import org.jackysoft.service.OperationLogService;
import org.jackysoft.util.Page;
import org.jackysoft.util.SpringSecurityUtils;

import com.google.common.collect.Maps;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

/**
 * @author qujiakang
 * 
 */
public class AbstractAction 
extends ActionSupport 
implements ModelDriven<Object> {
	/**
	 * 
	 */
	private static final long serialVersionUID = 7179100828686464980L;
	protected final Log log = LogFactory.getLog(this.getClass());
	protected final static String FAIL = "fail";
	protected final static String result = "success";
	protected static final String START = "start";
    protected static final String ADD = "add";
	protected static final String REMOVE = "remove";
	protected static final String CREATE = "create";
	protected static final String UPDATE = "update";
	protected static final String VALIDATE="validate";
	protected final static String INPUT = "input";
	protected final static String DEFAULT = SUCCESS;
	protected final static String DOWNLOAD="download";
	protected final static String STREAM="stream";
	protected final static String LIST=  "list";
	protected final static String JQGRID="jqgrid";
	protected final static String INDEX="index";
	protected final static String BEANLIST="beanlist";
	protected final static String STRINGLIST="stringlist";
	protected final static String BEANDATA="beandata";
	protected final static String MAPDATA="mapdata";
	protected final static String JSTREE="jstree";
	protected final static String IDLIST="idlist";
	protected final static String QUERY="query";
	protected final static String SORTED="sorted";
	protected final static String SELECT="select";
	protected final static String PAGER="pager";
	protected final static String NEWEDIT="newedit";
	protected final static String DATAIMPORT="dataimport";
	protected final static String OPTIONS="options";
	protected boolean mapDefaultActionMethod = true;	
	protected String ba83b88c_fdd6_46a8_89df_08949141ad2b9fbaa3ec_4ed2_4b78_9349_bfa802bf7912b4ac35ae_f1db_4081_bff5_57c04a839282b38388d2_467b_45fd_bfde_a58eb25a3c2ca50a51b8_9a75_493d_a8cc_52e7690cc8b34d896dfd_cc27_4ca8_9276_1e9f5c8bdf80dd7c4b5f_c730_48c5_9814_4a04babc7bd3543c234d_8d67_406f_b85f_dfe2949f270cbd719c0b_6992_48d2_a979_eef25873212f710d9509_19e5_4fbe_b20c_64662a6985bb="%&^@%#^#%##(&@#(&!@*&@!";
	protected Page pager;
	

	protected Collection<String> idList;
	protected Map<String,Object> resultMap = Maps.newHashMap();
	protected String jsonContent;
	private Boolean validating = false;
	private Class<?> type;
	private OperationLogService logService;
    protected String beanId;
    private String nd;
    private String _search ;
	/**
	 * 对象初始化方法
	 */

	@PostConstruct
	public void initilize() {

	}

	/**
	 * 对象销毁前调用
	 */
	@PreDestroy
	public void destory() {

	}

	public String index()throws Exception{
		return execute();
	}
	
	@Override
	public String execute() throws Exception {

		return SUCCESS;
	}

	public Object getModel() {

		return new Object();
	}
	

	public String submit() throws Exception {
		return "success";
	}

	public String input() throws Exception {
		return INPUT;
	}

	public String options() throws Exception{
		return OPTIONS;
	}
	

	public User getLoginUser() {
		return SpringSecurityUtils.getCurrentUser();
	}
	
	public String getJsonContent() {
		return jsonContent;
	}


	public void setJsonContent(String jsonContent) {
		this.jsonContent = jsonContent;
	}

	public Collection<String> getIdList() {
		return idList;
	}

	public void setIdList(Collection<String> idList) {
		this.idList = idList;
	}

	public void setResultMap(Map<String, Object> resultMap) {
		this.resultMap = resultMap;
	}

	public Map<String, Object> getResultMap() {
		return resultMap;
	}

	public Class<?> getType() {
		return type;
	}

	public void setType(Class<?> type) {
		this.type = type;
	}

	public Boolean isValidating() {
		return validating;
	}

	public Boolean getValidating(){
		return isValidating();
	}
	public void setValidating(Boolean validating) {
		this.validating = validating;
	}

	
	@Resource
	public void setLogService(OperationLogService logService) {
		this.logService = logService;
	}
	
	public void logAction(OperationLog opr){
		log.info("日志已被记录 : "+opr);
		this.logService.create(opr);
	}

	
	public Page getPager() {
		return pager;
	}

	public void setPager(Page pager) {
		this.pager = pager;
	}

	/**
	 * 是否映射默认拦截器
	 * @return
	 *   <dd>true 映射默认拦截器方法
	 *   <dd>false 不映射默认拦截器
	 * */
	public boolean isMapDefaultActionMethod() {
		return mapDefaultActionMethod;
	}

	public void setMapDefaultActionMethod(boolean mapDefaultActionMethod) {
		this.mapDefaultActionMethod = mapDefaultActionMethod;
	}

	public boolean isMapDefault(){
		return isMapDefaultActionMethod();
	}
	
	public void setMapDefault(boolean mapDefaultActionMethod) {
		setMapDefaultActionMethod(mapDefaultActionMethod);
	}

	public String getBeanId() {
		return beanId;
	}

	public void setBeanId(String beanId) {
		this.beanId = beanId;
	}

	public String getNd() {
		return nd;
	}

	public void setNd(String nd) {
		this.nd = nd;
	}

	public String get_search() {
		return _search;
	}

	public void set_search(String _search) {
		this._search = _search;
	}	
}
